var split_code = '';
var IE = document.all ? true : false;
var money_color ='ff6c00';
var sc = new Array;
for (var i=0;i<2;++i) sc[i]=String.fromCharCode(i+1);

function isUrl(string)
{
        string = string.toLowerCase();
        urlRegExp = /^(((ht|f)tp(s?))\:\/\/)([0-9a-zA-Z\-]+\.)+[0-9a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/
        return urlRegExp.test(string);
}

function open_win(url,win_x,win_y,scroll,win_name,resize)
{        
        var src_x = screen.width;
        var src_y = screen.height;

        tmp_MSIE = window.navigator.userAgent.indexOf("MSIE");
        if(tmp_MSIE && window.navigator.userAgent.indexOf("SV1") > tmp_MSIE)
        {   
                win_y = win_y + 40;
        }

        var x= (src_x - win_x)/2; 
        var y= (src_y - win_y)/2;

        if(!win_name) var win_name = 'window';

        open_name = window.open(url,win_name,'left='+ x +',top='+ y +',width='+ win_x +', height=' + win_y + ', menubar=no, scrollbars=' + scroll +', staus=no, resizable=' + resize + ', titlebar=no, toolbar=no, hotkey=0,closeable=no'); 
        open_name.focus();

        return open_name;
}

function move_center(win_x,win_y,left_pos)
{        
        var src_x = screen.width;
        var src_y = screen.height;

        win_y = win_y + 40;

        var x= (src_x - win_x)/2; 
        var y= (src_y - win_y)/2;

        if (left_pos)
                moveTo(left_pos,y);
        else
                moveTo(x,y);
        window.resizeTo(win_x,win_y);
}

function LTrim(str)
{
        var whitespace = new String(" \t\n\r");

        var s = new String(str);

        if (whitespace.indexOf(s.charAt(0)) != -1)
        {
                var j=0, i = s.length;

                while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                j++;

                s = s.substring(j, i);
        }

        return s;
}

function RTrim(str)
{
        var whitespace = new String(" \t\n\r");

        var s = new String(str);

        if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
        {
                var i = s.length - 1;       // Get length of string

                while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                i--;

                s = s.substring(0, i+1);
        }

        return s;
}


function Trim(str)
{
        return RTrim(LTrim(str));
}

function get_str_len(str) // 한글포함 실제 bytes 수 구하기
{
        var total_len = 0;
        for (var i=0;i<str.length;++i)
        {
                if (escape(str.charAt(i)).length>4) total_len += 2; // 한글이거나 2byte 문자이면...
                else  ++total_len;
        }

        return total_len;
}

function cut_string(string, limit)
{
        var inc = 0;
        var nbytes = 0;
        var msg = "";
        var msglen = string.length;

        for (i=0; i<msglen; i++)
        {
                var ch = string.charAt(i);
                if (escape(ch).length > 4) inc = 2;
                else if (ch == '\n')
                {
                        if (string.charAt(i-1) != '\r') inc = 1;
                }
                else if (ch == '<' || ch == '>') inc = 4;
                else inc = 1;

                if ((nbytes + inc) > limit) break;

                nbytes += inc;
                msg += ch;
        }

        return msg;
}

// base_64 encode/decode;

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function base64encode(input)
{
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        do
        {
                chr1 = input.charCodeAt(i++);
                chr2 = input.charCodeAt(i++);
                chr3 = input.charCodeAt(i++);

                enc1 = chr1 >> 2;
                enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
                enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
                enc4 = chr3 & 63;

                if (isNaN(chr2)) 
                {
                        enc3 = enc4 = 64;
                }
                else if (isNaN(chr3)) 
                {
                        enc4 = 64;
                }

                output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +  keyStr.charAt(enc3) + keyStr.charAt(enc4);

        } while (i < input.length);

        return output;
}

function base64decode(input)
{
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        do
        {
                enc1 = keyStr.indexOf(input.charAt(i++));
                enc2 = keyStr.indexOf(input.charAt(i++));
                enc3 = keyStr.indexOf(input.charAt(i++));
                enc4 = keyStr.indexOf(input.charAt(i++));

                chr1 = (enc1 << 2) | (enc2 >> 4);
                chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
                chr3 = ((enc3 & 3) << 6) | enc4;

                output = output + String.fromCharCode(chr1);

                if (enc3 != 64)
                {
                        output = output + String.fromCharCode(chr2);
                }
                if (enc4 != 64)
                {
                        output = output + String.fromCharCode(chr3);
                }
        } while (i < input.length);

        return output;
}


function reset_file_form(that_form)
// input type=file에서 취소 처리될 경우 file내용 모두 clear
// file 자체에 value 값을 채울 수 없으므로 모두 clear 할 수 밖에 없다.
{
        var total = that_form.elements.length;

        var resetVal = Array();

                // 현재 폼의 값을 저장
        for(var i=0;i<total;i++)
        {
                try
                {
                        obj = that_form.elements[i];
                        if(obj.type!='file')
                        {
                                resetVal[obj.name] = obj.value;
                        }
                }
                catch(e)
                {
                }
        }

        that_form.reset();

                // 저장된 폼값 표현
        for(var i=0;i<total;i++)
        {
                try
                {
                        obj = that_form.elements[i];
                        if(obj.type!='file' && obj.name != '')
                        {
                                obj.value = resetVal[obj.name];
                        }
                }
                catch(e)
                {
                }
        }
}

function is_email_addr(email)
{
//        var filter  = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
        var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;


        if (filter.test(email)) return 1;
        return 0;
}

function is_alpha_num(str)
{
        var check_string = /[A-Za-z0-9]*$/;
        return (str.match(check_string) == str);
}

function is_alphabet(str)
{
        var check_string = /[A-Za-z]*$/;
        return (str.match(check_string) == str);
}

function is_numeric(str)
{
        var check_string = /[0-9]*$/;
        return (str.match(check_string) == str);
}

function is_ip(str)
{
        var filter = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;

        if (filter.test(str))
        {
                var parts = str.split(".");
                if (parseInt(parseFloat(parts[0])) == 0)
                        return false;

                for (var i=0; i<parts.length; i++)
                        if (parseInt(parseFloat(parts[i])) > 255)
                                return false;
                return true;
        } 

        return false;
}

function auto_tab(form_name,elmnt,content)
{
        if (content.length==elmnt.maxLength)
        {
                var next=elmnt.tabIndex;

                for (var i=0;i<form_name.elements.length;++i)
                {
                        if (form_name.elements[i].tabIndex == next+1)
                                form_name.elements[i].focus();
                }
        }
}

function is_domain_name(domain)
{
        if (domain.charAt(0) == '-' || domain.charAt(domain.length-1) == '-')
        {
                alert('Domain is not available.\n\nDomain name may not begin or end with the hyphen "-".');
                return 0;
        }

        if (domain.indexOf(' ') != -1 || domain.indexOf('.') != -1)
        {
                alert('Domain is not available.');
                return 0;
        }

/*
        if (!is_alpha_num(domain.replace(/-/gi,'')) || domain == "www")
        {
                alert('"' + domain + '"is not available.\n\n Domain name may only contain letters  a - z, a hyphen "-" and digits 0 - 9 \n\n Please try again');
                return 0;
        }
*/
        return 1;
}

function make_popup_bottom_bar()
{
        var bar_height = 21;

        if(navigator.appName == "Netscape")
        { 
                var window_width = window.innerWidth;
                var window_height = window.innerHeight;
        }
        else if(navigator.appName == "Microsoft Internet Explorer")
        { 
                var window_width = document.body.clientWidth;
                var window_height = document.body.clientHeight;
        }

        document.getElementById('popup_bottom').style.pixelLeft = 0;
        document.getElementById('popup_bottom').style.pixelTop = window_height - bar_height;

        setTimeout("make_popup_bottom_bar()", 100);
}

function ie_security_captcha_login()
{
        if (navigator.appName == 'Microsoft Internet Explorer')
        {
                if (top.location != self.location) 
                        top.location = self.location;
        }
}

function what_is_warning(rn_list)
{
        open_win('/what_is_blocked/what_is_warning.php?'+rn_list,50,50,'no','what_is_warning');
}